<% @page_title = @topic.title %>
<% @monitoring = logged_in? && !Monitorship.count(:id, :conditions => ['user_id = ? and topic_id = ? and active = ?', current_user.id, @topic.id, true]).zero? %>

<div class="forums">
  <% content_for :right do -%>

    <h6><%= 'Voices'[:voices_title] %></h6>
    <p>
      <% @topic.voices.each do | user | %>
	<% unless user == nil -%>
        <%= link_to h(user.display_name), person_path(user.person) %><br/>
<% end -%>
      <% end %>
    </p>
  <% end # right content -%>

  <% if logged_in? && false %>
  <%# disabled by added false above -%>
    <% form_tag forum_topic_monitorship_path(@forum, @topic), :style => 'margin-top:0em; float:right;' do -%>
      <div>
        <input id="monitor_checkbox" type="checkbox" <%= "checked='checked'" if @monitoring %>
               onclick="if (this.checked) {<%= remote_function :url => forum_topic_monitorship_path(@forum, @topic) %>} else {<%= remote_function :url => forum_topic_monitorship_path(@forum, @topic), :method => :delete %>}" />
        <label id="monitor_label" for="monitor_checkbox"><%= @monitoring ? 'Monitoring topic'[] : 'Monitor topic'[] %></label>
        <%= hidden_field_tag '_method', 'delete' if @monitoring %>
        <%= submit_tag :Set, :id => 'monitor_submit' %>
      </div>
    <% end -%>
  <% end -%>

  <div class="crumbs">
    <%= link_to "Forums"[:forums_title], forums_path %> <span class="arrow">&rarr;</span>
    <%= link_to h(@topic.forum.name), forum_path(@topic.forum) %>
    <%
    page=session[:forum_page] ? session[:forum_page][@topic.forum.id] : nil
    if page and page!=1 %>
      <small style="color:#ccc">
        (<%= link_to 'page {page}'[:page, page], forum_path(:id => @topic.forum, :page => page) %>)
      </small>
    <% end %>
    <span class="arrow">&rarr;</span>
  </div>

  <div id="right">
    <%=  yield :right %>
  </div>

  <div class="contribution_title">
    <h1 id="topic-title" <%= %( onmouseover="$('topic_mod').show();" onmouseout="$('topic_mod').hide();") if logged_in? %>>

      <%= h @topic.title %>
      <% if @topic.locked? %>
        <span>(<%= 'locked'[] %>)</span>
      <% end %>
      <% if logged_in? %>
        <span style="display:none;" id="topic_mod">
          <% if @topic.editable_by?(current_user) -%>
            <%= link_to('edit'[], edit_forum_topic_path(@forum, @topic), :class => "utility") %> |
            <%= link_to('delete'[], forum_topic_path(@forum, @topic), :class => "utility", :method => :delete, :confirm => 'Delete this topic forever?'[:delete_topic_conf]) %>
          <% end -%>
        </span>
      <% end %>
    </h1>
  </div>

  <p class="subtitle">
    <%= feed_icon_tag @topic.title, forum_topic_path(@forum, @topic, :format => :rss) %>
    <%= '{count} post(s)'[(count=@topic.posts.size)==1 ? :post_count : :posts_count, number_with_delimiter(count)] %>,
    <%= '{count} voice(s)'[(count=@topic.voices.size)==1 ? :voice_count : :voices_count, number_with_delimiter(count)] %>
  </p>

  <%= will_paginate @posts %>

  <a name="<%= dom_id @posts.first %>" id="<%= dom_id @posts.first %>">&nbsp;</a>

  <table border="0" cellspacing="0" cellpadding="0" class="posts wide">
    <% for post in @posts do %>
        
        <tr class="post hentry" id="<%= dom_id post %>-row">
          <td class="author vcard">
            <div class="date">
              <a href="#<%= dom_id post %>" rel="bookmark">
                  <%= time_ago_in_words(post.created_at) %> ago
              </a>
            </div>
<% unless post.user == nil -%>
            <%= avatar_for post.user %>
<% end -%>
<% unless post.user == nil -%>
            <span class="fn"><%= link_to truncate(h(post.user.display_name), 15), person_path(post.user.person), :class => (post.user == @posts.first.user ? "threadauthor" : nil) %></span>
<% end -%>
<% unless post.user == nil -%>
            <% if post.user.admin? or post.forum.moderators.include?(post.user) %>
              <span class="admin">
                <% if post.user.admin? %>
                  <%= 'Administator'[:administrator_title] %>
                <% elsif post.forum.moderators.include?(post.user) %>
                  <%= 'Moderator'[:moderator_title] %>
                <% end %>
              </span>
            <% end %>
            <span class="posts"><%= '{count} post(s)'[(count=post.user.posts.size)==1 ? :post_count : :posts_count, number_with_delimiter(count)] %></span>
<% end -%>

            <% if logged_in? && post.editable_by?(current_user) -%>
              <p>
                <span class="edit">
                  <%= ajax_spinner_for "edit-post-#{post.id}", "spinner_bounce.gif" %>
                  <%= link_to_remote('Edit post'[],
                    {:url => edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post), :method => :get,
                      :before => "EditForm.init(#{post.id});", :condition => "!EditForm.isEditing(#{post.id})" },
                    {:href => edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post, :page => params[:page]), :class => "utility"}) %>
                </span>
              </p>
            <% end -%>


          </td>
          <td class="body entry-content" id="post-body-<%= post.id %>">
            <!--
            <%= link_to_function image_tag('clearbits/comment.gif', :class => 'icon reply'), "$('reply').toggle()" if logged_in? %>
            -->
            <%= post.body_html %>
          </td>
        </tr>

      <% end %>
    </table>

    <%= will_paginate @posts %>

    <% if logged_in? %>
      <div id="edit"></div>
      <% if @topic.locked? %>
        <p>
          <%= image_tag "savage_beast/clearbits/lock.gif", :class => "icon grey", :title => "Topic locked"[:topic_locked_title] %>
          <label>
            <%= 'This topic is locked'[:locked_topic] %>.</label>
        </p>
      <% else %>

        <p><%= link_to_function 'Reply to topic'[], "ReplyForm.init()", :class => "utility" %></p>

        <div id="reply" class="editbox">
          <div class="container">
            <%= content_tag 'p', h(flash[:bad_reply]), :class => 'notice' if flash[:bad_reply] %>
            <% form_for :post, :url => posts_path(:forum_id => @forum, :topic_id => @topic, :page => @topic.last_page) do |f| -%>
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td rowspan="2" width="70%">
                    <%= f.text_area :body, :rows => 8 %>
                  </td>
                  <td valign="top">


                    <h5><%= 'Formatting Help'[] %></h5>

                    <ul class="help">
                      <li><%= '*bold*'[:formatting_bold] %>
                        &nbsp; &nbsp; &nbsp;
                        <%= '_italics_'[:formatting_italics] %>
                        &nbsp; &nbsp; &nbsp;<br />
                        <%= 'bq. <span>(quotes)</span>'[:formatting_blockquote] %></li>
                      <li>"IBM":http://www.ibm.com</li>
                      <li><%= '* or # <span>(lists)</span>'[:formatting_list] %></li>
                    </ul>

                  </td>
                </tr>
                <tr>
                  <td valign="bottom" style="padding-bottom:15px;">
                    <%= submit_tag "Save Reply"[] %><span class="button_or">or <%= link_to_function 'cancel'[], "$('reply').hide()" %></span>
                  </td>
                </tr>
              </table>
            <% end -%>
          </div>
        </div>
        <%= javascript_tag "$('reply').hide();"%>
      <% end %>
    <% end %>

    <div class="crumbs" style="margin-top:1.1em;">
      <%= link_to "Forums"[:forums_title], forums_path %> <span class="arrow">&rarr;</span>
      <%= link_to h(@topic.forum.name), forum_path(@topic.forum) %> <span class="arrow">&rarr;</span>
    </div>
  </div>